<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>模块管理</title>
		<link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
		<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
</head>
<body>
<div class="form-wrapper" id="moduleDiv">
    	<div class="form-title">
       		 <span class="ttcorner"></span>
             <h3>
                <span class="text">模块管理</span>
             </h3>
        </div>
        <form name="theForm" method="post">
			<input type="hidden" name="theForm.PARENT_ID" value="${theForm.PARENT_ID}"></input>
			<input type="hidden" name="theForm.MODULE_LEVEL" value="${theForm.MODULE_LEVEL}"></input>
		</form>
        <div class="box-in">
            <table border="0" cellspacing="0" cellpadding="0" class="table-03">
	            <tr>
		         	<td class="monitor_bg1" height="13" align ="right" nowrap>
			     		模块名称：
			         	<input type="text" class="input-style1" name="theForm.SEARCH_KEYWORD_NAME"/>
			         	<input type="button" class="btn-style02" id="btn-search" value="查询" />
			         </td>
		   		</tr>
            </table>
        </div>
        <div class="title-style"><a class="fold-tip"></a></div>
        <div class="block02">
      		<div class="title-style02">
				<input class="btn-style02" type="button" id="btn-add" value="增加">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-edit" value="修改">&nbsp;&nbsp;
				<!-- <input class="btn-style02" type="button" id="btn-copy" value="拷贝">&nbsp;&nbsp; -->
				<input class="btn-style02" type="button" id="btn-del" value="删除">
            </div>
            <table id="gridTable">
			</table>
			<div id="gridPager">
			</div>
       	</div>
</div>
<div class="form-wrapper" id="noModuleDiv" style="display:none">
    	<div class="form-title">
       		 <span class="ttcorner"></span>
             <h3>
                <span class="text">已到最后一级，不能再添加子菜单</span>
             </h3>
        </div>
</div>        

</body>
<script type="text/javascript">
		$(document).ready(function(){
			var level = $("input[name='theForm.MODULE_LEVEL']").val();
			if(level=="3"){
				$("#moduleDiv").hide();
				$("#noModuleDiv").show();
			}
		});
		
			$(function(){
				$(".title-style a.fold-tip").toggle(toggletip,toggletip);
				function toggletip() {
					if ($(this).attr("class").split("unfold-tip").length > 1) {
						$(this).removeClass("unfold-tip");
						$(this).parents().prev(".box-in").show("fast");
					} else {
						$(this).addClass("unfold-tip");
						$(this).parents().prev(".box-in").hide("fast");
					}
				}
				$('#sel1').click(function(){
										  var height = $(window.parent.document.getElementById('sideframe')).height();
						$(window.parent.document.getElementById('sideframe')).css("display","none").next(".sideframe-collapse").css({"display":"block","height":height});
				})
			})
			
			$(function(){$("#gridTable").jqGrid({
					url: "loadListModulesQueryJson.do",
					datatype: "json",
					mtype: "POST",
					height: "100%",
					autowidth: true,
					colNames:['模块ID', '模块名称', '模块路径', '是否刷新', '显示顺序', '是否有效'],
					colModel:[
						{name:'MODULE_ID',index:'MODULE_ID',hidden:true},
						{name:'MODULE_NAME',index:'MODULE_NAME'},
						{name:'MODULE_PATH',index:'MODULE_PATH',formatter:function(value){
							if(value=="null"){
								value = "";
							}
							return value;
						}},
						{name:'IS_REFRESH',index:'IS_REFRESH',formatter: function(value){
							if (value=="1"){
								return "是";
							} else {
								return "否";
							}
						}},
						{name:'VIEW_ORDER',index:'VIEW_ORDER'},
						{name:'MODULE_ENABLE',index:'MODULE_ENABLE',formatter: function(value){
							if (value=="1"){
								return "是";
							} else {
								return "否";
							}
						}}
					],
					viewrecords: true,
					rowNum: 15,
					rowList: [10,15,30],
					jsonReader: {
						root: 'rows',
						page: 'page',
						total: 'total',
						records: 'records',
						repeatitems: false,
						subgrid: {
					        root: 'rows',
							page: 'page',
							total: 'total',
							records: 'records',
							repeatitems: false
					    }      
					},
					pager: "#gridPager",
					hidegrid: true,
					multiselect: true,
					beforeRequest:function(){
						var postData = {};
						$(":input[name^='theForm.']").each(function(){
							postData[$(this).attr("name")] = $(this).val();
						});
						$.extend($("#gridTable").getGridParam("postData"), postData);
					}
				});
				
			}); 
			
			
			$("#btn-search").click(function(){
				$("#gridTable").trigger("reloadGrid",[{page:1}]);
			});
			
			$("#btn-add").click(function(){
				$("form[name='theForm']").append("<input type='hidden' name='theForm.ISMP_JSP_COMMAND' value='add'/>");
				$("form[name='theForm']").attr("action","<s:url action='editModule' namespace='/'/>").submit();
			});
			$("#btn-del").click(function(){
			 	var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                if (idArr.length == 0) {
                    alert("请先选择要删除的记录!");
                    return;
                }
				if(confirm("是否删除所选的记录?")){
					var MODULE_ID = "";
                    for (var one in idArr){
                    	var data = jQuery("#gridTable").jqGrid('getRowData',idArr[one]);
                    	MODULE_ID += data.MODULE_ID + ",";
                    }
                    if(MODULE_ID.length>0){
                    	MODULE_ID = MODULE_ID.substring(0,MODULE_ID.length-1);
                    }
                    
					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action="delModule" namespace='/'/>?theForm.MODULE_ID="+MODULE_ID+"&theForm.PARENT_ID="+$("input[name='theForm.PARENT_ID']").val(),
						success: function(data){
	                        if (data != "true"){
								alert(data);
	                        }else{
	                       		$("#gridTable").trigger('reloadGrid');
	                       		alert("删除成功");
	                       		parent.refreshNode();
	                       	}
						},
						error:function(xhr){  
							show_error(xhr);
						}
					});	
                }
			});
			$("#btn-edit").click(function() {
				var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
				switch (idArr.length) {
					case 0:
						alert("请先选择要修改的记录!");
						break;
					case 1:
						var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
						var MODULE_ID = data.MODULE_ID;
						$("form[name='theForm']").append("<input type='hidden' name='theForm.ISMP_JSP_COMMAND' value='modify'/>");
						$("form[name='theForm']").append("<input type='hidden' name='theForm.MODULE_ID' value='"+MODULE_ID+"'/>");
						$("form[name='theForm']").attr("action","<s:url action='editModule' namespace='/'/>");
						$("form[name='theForm']").submit();
						break;
					default:
						alert("一次只能修改一条记录!");
				}
			}); 
		</script>
</html>            
